package com.accp.controller;

import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.accp.pojo.RoomType;
import com.accp.service.RoomTypeService;

@Controller
public class RoomTypeController {
	@Autowired
	private RoomTypeService roomTypeService;
	@RequestMapping("/roomList")
	private String room(Model model){
		List<RoomType> getList=roomTypeService.getUser();
		model.addAttribute("List", getList);
		return "roomType";	
	}
	@RequestMapping("/add")
	public String add(String roomtypename ,Double roomprice, HttpServletRequest request,HttpServletResponse response)throws Exception{
		RoomType re=new RoomType();
		re.setRoomtypename(roomtypename);
		re.setRoomprice(roomprice);
		int count=roomTypeService.insert(re);
		if(count>0){
			System.out.println(count);
			return "redirect:roomList";
		}else{
			System.out.println("回来了");
			RequestDispatcher dispatcher=request.getRequestDispatcher("addRoomType.jsp");
			dispatcher.forward(request, response);
		}
		return null;
	}
	@RequestMapping("/addRoomTypee")
	public String lo(){	
		return "addRoomType";
	}
	
	
	@RequestMapping("/roomListU")
	private String roomListU(Model model){
		List<RoomType> getList=roomTypeService.getUser();
		model.addAttribute("List", getList);
		return "roomTypeU";	
	}
	

	@RequestMapping("/delete")
	public String delete(int roomtypeid){
		
		
		
		
		try {
			int result=roomTypeService.deleteByPrimaryKey(roomtypeid);
			if (result==1) {
				return "redirect:roomList";
			}else{
				System.out.println("删除失败");
				return "redirect:roomList";
			}
		} catch (Exception e) {
			return "roomtypeshibai";
		}
		
		
	}
	
	
	
}
